package jk.spider.core.throttle.impl;

import java.util.concurrent.TimeUnit;

import jk.spider.core.throttle.Throttle;

public class RandomThrottleImpl implements Throttle {
	
	protected int min;
	protected int max;
	
	public RandomThrottleImpl( int minThinkTime, int maxThinkTime ) {
		this.min = minThinkTime;
		this.max = maxThinkTime;
	}

	public void throttle() {
		long seconds = min + (int)(Math.random() * ( max-min ) );
		try {
            TimeUnit.MILLISECONDS.sleep(seconds);
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
        }
	}
}
